package 二叉树;

//https://leetcode-cn.com/problems/same-tree/
public class _100_相同的树 {
     public class TreeNode {
         int val;
         TreeNode left;
         TreeNode right;
         TreeNode() {}
         TreeNode(int val) { this.val = val; }
         TreeNode(int val, TreeNode left, TreeNode right) {
             this.val = val;
             this.left = left;
             this.right = right;
         }
     }
    public boolean isSameTree(TreeNode p, TreeNode q) {
         //如果都是null 是相同的
        if (p == null && q == null) return true;
        //如果有一个不是，是不相同的
        if (p == null || q == null) return false;
        //如果的他们的值不一样是相同的
        if (p.val != q.val) return false;
        //递归判断他们的左右子树是否相同
        return  isSameTree(p.left,q.left) && isSameTree(p.right,q.right);
    }
}
